package com.ruoyi.web.controller.dp;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dp.domain.DpDangerousPoint;
import com.ruoyi.dp.service.IDpDangerousPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(description="危险点管理")
@RestController
@RequestMapping("/dp/dangerousPoint")
public class DpDangerousPointController extends BaseController {

    @Autowired
    IDpDangerousPointService dpDangerousPointService;

    @ApiOperation("查询危险点信息")
    @GetMapping("/list")
    public TableDataInfo list(DpDangerousPoint dpDangerousPoint)
    {
        startPage();
        return getDataTable(dpDangerousPointService.selectDpDangerousPointList());
    }

    @ApiOperation("获取危险点详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        DpDangerousPoint dpDangerousPoint = dpDangerousPointService.selectDpDangerousPointById(ID);
        return success (dpDangerousPoint);
    }

    @ApiOperation("新增危险点")
    @Log(title = "危险点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DpDangerousPoint dpDangerousPoint) {
        dpDangerousPoint.setCreateTime(new Date());
        return toAjax(dpDangerousPointService.insertDpDangerousPoint(dpDangerousPoint));
    }

    @ApiOperation(value = "修改危险点")
    @Log(title = "危险点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DpDangerousPoint dpDangerousPoint)
    {
        dpDangerousPoint.getName();
        return toAjax(dpDangerousPointService.updateDpDangerousPoint(dpDangerousPoint));
    }


    /**
     * 删除危险点
     */
    @ApiOperation(value = "删除危险点")
    @Log(title = "危险点", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(dpDangerousPointService.deleteDpDangerousPointByIds(IDs));
    }
}
